//
// Created by 86136 on 2024/11/28.
//
#include "chatserver.hpp"
#include "chatservice.hpp"
#include <iostream>
#include <csignal>
using namespace std;

// 服务器ctrl+c结束后，重置user的状态信息
void resetHandler(int) {
    ChatService::instance()->reset();
    exit(0);
}


int main(int argc, char ** argv) {
    signal(SIGINT, resetHandler);
    EventLoop loop; // epoll
    InetAddress addr("127.0.0.1", atoi(argv[1]));
    ChatServer server(&loop, addr, "ChatServer");

    server.start(); // listen 和 epoll_ctl 添加到 epoll上
    loop.loop();    // epoll_wait——以阻塞方式等待新用户连接，已连接用户的读写事件等

    return 0;
}
